package com.primal.controller;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.primal.bean.Args;
import com.primal.bean.RequestArgs;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author:whh
 * @date: 2024-01-18 22:10
 * <p></p>
 */
@RestController
public class TestController {

    @RequestMapping(path = "/api/{args}",method = RequestMethod.GET)
    public void fun(@PathVariable("args") String args, HttpServletRequest request){
        System.out.println(args);

        request.getSession().setAttribute("name","syx");
    }


    @RequestMapping(path = "/api/p",method = RequestMethod.POST)
    public void fun2(@RequestParam("args") String args){
        System.out.println(args);
    }

    @RequestMapping(path = "/api/q",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> fun3(@RequestBody RequestArgs requestArgs, HttpServletRequest request){

        Map<String,Object> result = new HashMap<>();
        String s = JSON.toJSONString(requestArgs);
        Map map = JSON.parseObject(s, Map.class);
        result.put("data",map);
        return result;

    }


    @RequestMapping(path = "/api/q",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> fun4(Args args, HttpServletRequest request){

        Map<String,Object> result = new HashMap<>();
        Object name = request.getSession().getAttribute("name");
        System.out.println(name+"----------------");
        return result;

    }
}
